package simulation;

import streaming.ComparatorModule;
import streaming.StreamingConfig;

public class ComparatorModulePeriodicUpdate implements EventHandler {
	ComparatorModule comparatorModule;
	Simulator sim;
	
	public ComparatorModulePeriodicUpdate(ComparatorModule comparatorModule) {
		this.setComparatorModule(comparatorModule);
		this.setSim(Simulator.getInstance());
	}
	
	public void addEvent() {
		double time = this.getSim().getTime() + this.getInterval();
		if (Math.abs(time - Math.round(time)) < 0.00001)
			time = Math.round(time);
		this.getSim().addEvent(time, this);
	}
	
	public void run(double time) {
		this.getComparatorModule().updateStatus();
	}

	/* Getters and Setters */

	public ComparatorModule getComparatorModule() {
		return comparatorModule;
	}

	public void setComparatorModule(ComparatorModule comparatorModule) {
		this.comparatorModule = comparatorModule;
	}

	public Simulator getSim() {
		return sim;
	}

	public void setSim(Simulator sim) {
		this.sim = sim;
	}

	public double getInterval() {
		return StreamingConfig.COMPARATOR_MODULE_UPDATE_INTERVAL;
	}
}
